<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <p><input type="button" value="打开窗口" onclick="openWin()"</p>
    <p><input type="button" value="关闭窗口" onclick="closeWin()"</p>
    <p><input type="button" value="检测窗口是否关闭" onclick="checkWin()"</p>
    <script>
        var myWindow;
        function openWin(){
            myWindow = window.open('','newWin','width=400,height=200,left=200');
            myWindow.document.write('<p>窗口名称为：'+myWindow.name+'</p>');
            myWindow.document.write('<p>当前窗口的父窗口地址:'+window.parent.location+'</p>');
        }
        function closeWin(){
            myWindow.close();
        }
        function checkWin(){
            if(myWindow){
                var str = myWindow.closed ? '窗口已关闭！':'窗口未关闭!';
            }
            else{
                var str = '窗口没有被打开！';
            }
            document.getElementById('msg').innerHTML = str;
        }        
    </script>
</body>
</html>